Skip to content

Create Python program for text-to-image generation and OCR extraction #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 16, 2025

This PR implements a complete Python program that generates images with embedded text and extracts the text using OCR (Optical Character Recognition).

Features Added

  • Text-to-Image Generation: Creates images with white background and black text using the Pillow library
  • OCR Text Extraction: Extracts text from generated images using pytesseract
  • Command-line Interface: Accepts two arguments - text to embed and output filename
  • Comprehensive Error Handling: Handles missing arguments, image generation failures, and OCR processing errors
  • Requirements Management: Added requirements.txt with necessary dependencies

Usage

python text_ocr.py "Hello from GitHub Copilot!" test.png

Output:

Generated image: test.png
Extracted Text:
----------------
Hello from GitHub Copilot!

Error Handling

The script includes robust error handling for:

  • Missing or invalid command-line arguments
  • Empty text or filename inputs
  • Image generation failures (invalid paths, permissions)
  • OCR processing failures (missing files, corrupted images)

Dependencies

  • Pillow>=10.0.0 - For image generation and manipulation
  • pytesseract>=0.3.0 - For OCR text extraction
  • System requirement: tesseract-ocr package

Additional Files

  • Added .gitignore to exclude Python cache files and generated test images
  • Added requirements.txt for easy dependency installation

The implementation follows Python best practices with proper error handling, documentation, and modular function design.

Fixes #1.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 16, 2025 08:55
…extraction

Co-authored-by: ashishkurmi <100655670+ashishkurmi@users.noreply.github.com>
Co-authored-by: ashishkurmi <100655670+ashishkurmi@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Create a Python Program to Generate an Image with Text and Extract the Text Using OCR Create Python program for text-to-image generation and OCR extraction Jul 16, 2025
Copilot finished work on behalf of ashishkurmi July 16, 2025 08:57
@Copilot Copilot AI requested a review from ashishkurmi July 16, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a Python Program to Generate an Image with Text and Extract the Text Using OCR
2 participants